﻿//_______________________________________________________________________________________________________________________
// Copy Right (c) 2010, 2011 SapiensIT Consulting GmbH, all rights reserved
//_______________________________________________________________________________________________________________________
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//_______________________________________________________________________________________________________________________
// PROJECT:     sapiens.at.SharePoint (SharePoint 2010/V4)
//_______________________________________________________________________________________________________________________
// VERSION:     2.0
//_______________________________________________________________________________________________________________________
// DESCRIPTION: 
//_______________________________________________________________________________________________________________________
// LICENSE:     Different licens Types apply to different file types:
//               - Source code files are governed by the MICROSOFT PUBLIC LICENSE (Ms-PL)
//               - Binary files are governed by MSDN CODE GALLERY BINARY LICENSE
//               - Documentation files are governed by CREATIVE COMMONS ATTRIBUTION 3.0 LICENSE
//
//               The licenses can be found at the projects source location.
//               If you do not agree, don't use it!
// 
//_______________________________________________________________________________________________________________________
// Start SharePoint Branding, visit http://www.cliggin.com! Visit us on http://www.sapiens.at! Tell your friends! 
//_______________________________________________________________________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Sapiens.at.SharePoint.Entities
{
    /// <summary>
    /// Interface that defines structure for all entities.
    /// </summary>
    /// <seealso cref="Entity"/>
    public interface IEntity
    {
        /// <summary>
        /// Gets the ID of the listitem.
        /// </summary>
        int Id { get; }

        /// <summary>
        /// Gets or sets the unique ID
        /// </summary>
        Guid Unique_ID { get; set; }

        /// <summary>
        /// Gets or sets the name of the contenttype
        /// </summary>
        string ContentType { get; set; }

        /// <summary>
        /// Gets or sets the contenttype id
        /// </summary>
        SPContentTypeId ContentTypeId { get; set; }
        
        /// <summary>
        /// Gets the fileleafref
        /// </summary>
        string FileLeafRef { get; }

        /// <summary>
        /// Gets the object type
        /// </summary>
        string FSObjType { get; }

        /// <summary>
        /// Gets or sets the Title of the listitem.
        /// </summary>
        string Title { get; set; }

        /// <summary>
        /// Gets the author
        /// </summary>
        SPUser Author { get; set; }

        /// <summary>
        /// Gets the editor
        /// </summary>
        SPUser Editor { get; set; }

        /// <summary>
        /// Returns true, if any of the fields got modified; otherwise false.
        /// This is not intended to tell whether the user has changed fields in the edit form.
        /// </summary>
        bool IsModified { get; }
        /// <summary>
        /// Gets a list of the fieldnames of the changed fields.
        /// </summary>
        IEnumerable<string> ModifiedFields { get; }

        /// <summary>
        /// Gets the listitem that this entity represents.
        /// </summary>
        SPListItem ListItem { get; }
        /// <summary>
        /// Gets the parentItem if the <see cref="ListItem"/> is in a folder. Otherwise null.
        /// </summary>
        SPListItem ParentItem { get; }
        /// <summary>
        /// Gets the list of this entity.
        /// </summary>
        SPList List { get; }
        /// <summary>
        /// Gets the web of this entity.
        /// </summary>
        SPWeb Web { get; }

        /// <summary>
        /// Gets all children of this entity.
        /// </summary>
        /// <returns></returns>
        IEnumerable<IEntity> GetChildren();
        /// <summary>
        /// Gets all children returned by a query.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        IEnumerable<IEntity> GetChildren(SPQuery query);

        /// <summary>
        /// Gets all children of this entity in a certain type.
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        IEnumerable<TEntity> GetChildren<TEntity>() where TEntity : IEntity;
        /// <summary>
        /// Gets all children of a certain content type.
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="cTypeId"></param>
        /// <returns></returns>
        IEnumerable<TEntity> GetChildren<TEntity>(SPContentTypeId cTypeId) where TEntity : IEntity;
        /// <summary>
        /// Gets all children returned by a query in a certain type.
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="query"></param>
        /// <returns></returns>
        IEnumerable<TEntity> GetChildren<TEntity>(SPQuery query) where TEntity : IEntity;

        /// <summary>
        /// Runs a code block in elevated privileges and passes this entity in an elevated context.
        /// </summary>
        void RunWithElevatedPrivileges<TEntity>(Action<TEntity> privilegedCode);

        /// <summary>
        /// Deletes the entity.
        /// </summary>
        void Delete();

        /// <summary>
        /// Deletes the entity.
        /// </summary>
        /// <param name="enableEvents">true, to enable eventfiring; otherwise false</param>
        void Delete(bool enableEvents);

        /// <summary>
        /// Moves the entity into the recycle bin.
        /// </summary>
        void Recycle();

        /// <summary>
        /// Moves the entity into the recycle bin.
        /// </summary>
        /// <param name="enableEvents">true, to enable eventfiring; otherwise false</param>
        void Recycle(bool enableEvents);
        /// <summary>
        /// Updates the entity without changing the editor.
        /// </summary>
        void SystemUpdate();
        /// <summary>
        /// Updates the entity without changing the editor.
        /// </summary>
        /// <param name="enableEvents">true, to enable eventfiring; otherwise false</param>
        void SystemUpdate(bool enableEvents);
        /// <summary>
        /// Updates the entity without changing the editor.
        /// </summary>
        /// <param name="enableEvents">true, to enable eventfiring; otherwise false</param>
        /// <param name="incrementListItemVersion"></param>
        void SystemUpdate(bool enableEvents, bool incrementListItemVersion);
        /// <summary>
        /// Updates the entity.
        /// </summary>
        void Update();
        /// <summary>
        /// Updates the entity.
        /// </summary>
        /// <param name="enableEvents">true, to enable eventfiring; otherwise false</param>
        void Update(bool enableEvents);
    }
}
